import {expect} from "chai";
import { Vec4 } from "../src/Vec4";
import { Mat4 } from "../src/Mat4";
import { Quat } from "../src/Quat";
describe("Vec4", function () {
    before(function() {
        console.log("开始自动化测试Vec4...");
    });

    after(function() {
        console.log("结束...");
    });
    beforeEach(function() {
    });

    afterEach(function() {
    });

    it('#constructor', function () {
        let vec=new Vec4();
        expect(vec.equal([0,0,0,0])).to.equal(true);
    });
    it('#x', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.x).to.equal(2);
    });
    it('#y', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.y).to.equal(3);
    });
    it('#z', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.z).to.equal(4);
    });
    it('#w', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.w).to.equal(5);
    });
    it('#toString', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.toString()).to.equal("Vec4(2,3,4,5)");
    });
    it('#copy', function () {
        let vec=new Vec4([2,3,4,5]);
        let o=new Vec4([2,3,4,0]);
        vec.copy(o)
        expect(vec.toString()).to.equal("Vec4(2,3,4,0)");
    });
    it('#clone', function () {
        let vec=new Vec4([2,3,4,5]);
        let vec2=vec.clone();
        expect(vec2.equal(vec)).to.equal(true);
    });
    it('#add', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.add([1,1,1,1])
        expect(vec.toString()).to.equal("Vec4(3,4,5,6)");
    });
    it('#sub', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.sub([1,1,1,1])
        expect(vec.toString()).to.equal("Vec4(1,2,3,4)");
    });
    it('#multiply', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.multiply([2,3,4,5])
        expect(vec.toString()).to.equal("Vec4(4,9,16,25)");
    });
    it('#div', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.div([2,3,2,1])
        expect(vec.toString()).to.equal("Vec4(1,1,2,5)");
    });
    it('#scale', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.scale(2)
        expect(vec.toString()).to.equal("Vec4(4,6,8,10)");
    });
    it('#length', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.length()).to.equal(Math.sqrt(54));
    });
    it('#distance', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.distance([0,0,0,0])).to.equal(Math.sqrt(54));
    });
    it('#negate', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.negate();
        expect(vec.toString()).to.equal("Vec4(-2,-3,-4,-5)");
    });
    it('#lerp', function () {
        let vec=new Vec4([2,4,4,6]);
        vec.lerp(0.5);
        expect(vec.equal([1,2,2,3])).to.equal(true);
    });
    it('#inverse', function () {
        let vec=new Vec4([2,2,2,2]);
        vec.inverse();
        expect(vec.toString()).to.equal("Vec4(0.5,0.5,0.5,0.5)");
    });
    it('#abs', function () {
        let vec=new Vec4([2,-3,4,5]);
        vec.abs();
        expect(vec.toString()).to.equal("Vec4(2,3,4,5)");
    });
    it('#dot', function () {
        let vec=new Vec4([2,3,4,5]);
        expect(vec.dot([2,2,2,2])).to.equal(28);
    });
    it('#cross', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.cross([1,0,0,1],[0,1,0,1])
        expect(vec.equal([4,4,0,-4])).to.equal(true);
    });
    it('#cross', function () {
        let vec=new Vec4([2,3,4,5]);
        vec.cross([1,0,0,1],[0,1,0,1])
        expect(vec.equal([4,4,0,-4])).to.equal(true);
    });
    it('#transformMat4', function () {
        let vec=new Vec4([2,3,4,5]);
        let mat4=new Mat4();
        mat4.fromRotation(Math.PI/2,[0,0,1]);
        vec.transformMat4(mat4);
        expect(vec.equal([-3,2,4,5])).to.equal(true);
    });
    it('#transformQuat', function () {
        let vec=new Vec4([2,3,4,5]);
        let quat=new Quat();
        quat.setAxisAngle([0,0,1],Math.PI/2);
        vec.transformQuat(quat);
        expect(vec.equal([-3,2,4,5])).to.equal(true);
    });
    
})